package com.imut.intercepter;

import com.imut.exception.BusinessException;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @Author jiangYaPeng
 * @Date 2025-07-02 15:20
 */

public class LoginIntercepter implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();

        String token = (String) session.getAttribute("token");
        if (ObjectUtils.isEmpty(token)){
            response.sendRedirect("/login");
        }
        return true;

    }


}
